package com.ssx.cloud.controller;

import com.ssx.cloud.entity.Admin;
import com.ssx.cloud.entity.CommonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

/**
 * @Package com.ssx.cloud.controller
 * @ClassName OrderController
 * @Copyright: Copyright (c) 2020
 * @Date 2020/11/19 16:13
 * @Company www.sudaoxi.com.cn
 * @Author 苏道羲
 * @Version 1.0
 * @Description
 */
@RestController
@Slf4j
public class OrderController {
    @Resource
    private RestTemplate restTemplate;

    //单机版
//    private static final String URL="http://localhost:8001";
    //集群版，使用微服务名称
    private static final String URL="http://CLOUD-PAYMENT-SERVICE";

    @GetMapping("/consumer/get/{id}")
    public CommonResult<Admin> getById(@PathVariable("id") Integer id) {
        return restTemplate.getForObject(URL+"/admin/get/"+id,CommonResult.class);
    }

    @GetMapping("/consumer/add")
    public CommonResult<Admin> add(Admin admin) {
        return restTemplate.postForObject(URL+"1/admin/add",admin,CommonResult.class);
    }

}
